/**
 * 
 */
package com.kavitha.normal.web;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author Vijayan Srinivasan
 * @since May 1, 2013 3:40:16 PM
 * 
 */
public class MySecondServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	private Log log = LogFactory.getLog(getClass());

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		log.info("Request recevied");
		Calculator calculator = new Calculator();
		try {
			BeanUtils.populate(calculator, req.getParameterMap());
		} catch (IllegalAccessException e) {
		} catch (InvocationTargetException e) {
		}

		RequestDispatcher dispatcher = req.getRequestDispatcher("second.jsp");
		req.setAttribute("result", calculator.result());
		dispatcher.forward(req, resp);
	}

}